<?php

class Application_Model_dataDAO_KhachHangDAO extends Zend_Db_Table_Abstract implements Application_Model_dataDAOInf_KhachHangDAOInf {
	protected $_name = "tb_khachhang";
	protected static $_instance = null;
	
	public static function getInstance() {
		if (self::$_instance == null) {
			self::$_instance = new self ();
		}
		return self::$_instance;
	}
	/**
	 * @param unknown_type $idKhachHang
	 */
	public function getKhachHang($idKhachHang) {
		$db = Application_Model_dataDAO_DBConnect::conn ();
		$khachHang = new Application_Model_bean_KhachHang ();
		
		try {
			$statement = "SELECT * FROM tb_khachhang where maKhachHang=" . $idKhachHang;
			$result = $db->fetchRow ( $statement );
			if (count ( $result ) > 0) {
				$khachHang->setHoVaTen ( $result ['hoVaTen'] );
				$khachHang->setCmnd ( $result ['cmnd'] );
				$khachHang->setDiaChi ( $result ['diaChi'] );
				$khachHang->setSoDienThoai ( $result ['soDienThoai'] );
				$khachHang->setEmail ( $result ['email'] );
			} else
				$khachHang = null;
		} catch ( Zend_Db_Exception $e ) {
			echo $e->getMessage ();
		}
		return $khachHang;
		
	//		$sql = $this->select ();
	//		$sql->where ( 'maKhachHang=?', $idKhachHang );
	//		$result = $this->fetchAll ( $sql );
	//		$this->getAdapter ()->closeConnection ();
	//		return $result;
	}
	/**
	 * @param unknown_type $hoVaTen
	 * @param unknown_type $cmnd
	 * @param unknown_type $diaChi
	 * @param unknown_type $soDienThoai
	 * @param unknown_type $email
	 */
	public function themKhachHang($hoVaTen, $cmnd, $diaChi, $soDienThoai, $email) {
		$result = 0;
		try {
			$db = Application_Model_dataDAO_DBConnect::conn ();
			$data = array ("hoVaTen" => $hoVaTen, "cmnd" => $cmnd, "diaChi" => $diaChi, "soDienThoai" => $soDienThoai, "email" => $email );
			$db->insert( 'tb_khachhang', $data);
			$result=$db->lastInsertId();
			$db->closeConnection();
		} catch ( Zend_Db_Exception $e ) {
			echo $e->getMessage ();
		}
		return $result;
	}

}

?>